//
//  ZWLDatePickerView.m
//  FBSnapshotTestCase
//
//  Created by lwz on 2018/6/4.
//

#import "ZWLDatePickerView.h"

@interface ZWLDatePickerView()
@property (unsafe_unretained, nonatomic) IBOutlet UIDatePicker *datePickerView;

@end

@implementation ZWLDatePickerView

+ (instancetype)createFromXib {

    NSBundle *bundle = [NSBundle bundleForClass:[self class]];
    return [bundle loadNibNamed:@"ZWLDatePickerView" owner:self options:nil][0];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.datePickerView.backgroundColor = [UIColor whiteColor];
    UIGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction)];
    [self addGestureRecognizer:tap];
}

- (IBAction)cancelAction:(id)sender {
    [self removeFromSuperview];
}

- (IBAction)comfirmAction:(id)sender {
    [self removeFromSuperview];
    if ([self.delegate respondsToSelector:@selector(zwlDatePickerView:DidSelectedDate:)]) {
        [self.delegate zwlDatePickerView:self DidSelectedDate:self.datePickerView.date];
    }
}

- (void)tapAction {
    [self dismiss];
}

- (void)showWithDate:(NSDate *) date {
    self.datePickerView.date = date;
    self.frame = [UIScreen mainScreen].bounds;
    [[UIApplication sharedApplication].keyWindow addSubview:self];
}

- (void)dismiss {
    [self removeFromSuperview];
}

@end
